package com.cfl.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cfl.user.service.UserService;
import com.cfl.utils.AppResponse;
import com.cfl.utils.Constant;

@Controller
public class UserController {
	
	@Autowired
	private UserService userService;
	
	/**
	 * 登录
	 * @param name	用户名
	 * @param password	密码
	 * @return
	 */
	@RequestMapping("login")
	@ResponseBody
	public Object login(String name, String password) {
		
		try {
			return userService.login(name, password);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new AppResponse("-1", Constant.error);
	}
	
	/**
	 * 注册
	 * @param name 用户名
	 * @param password	密码
	 * @return
	 */
	@RequestMapping("register")
	@ResponseBody
	public Object register(String name, String password) {
		try {
			return userService.register(name, password);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new AppResponse("-1", Constant.error);
	}
}
